package com.qujia.station.controller;


import com.alibaba.fastjson.JSONObject;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.station.service.IThirdPartyWeChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Api("第三方平台对接接口")
@RestController
@RequestMapping("/thirdParty/weChat")
@Slf4j
public class ThirdPartyWeChatContrller {

    @Autowired
    private IThirdPartyWeChatService thirdPartyWeChatService;


    @ApiOperation(value = "微信验证授权接口")
    @PostMapping(value = "/ticketNotify",  produces = "text/html;charset=UTF-8")
    public String ticketNotify(HttpServletRequest request, HttpServletResponse response) {
        return thirdPartyWeChatService.ticketNotify(request,response);

    }

    @GetMapping("/bindWxNotify")
    @ApiOperation("商家授权回调")
    public void bindWxNotify(@RequestParam("auth_code") String authCode, @RequestParam("expires_in") Integer expiresIn,HttpServletResponse resp)throws IOException {
        this.thirdPartyWeChatService.bindWxNotify(authCode, expiresIn,resp);
    }


    @GetMapping("/getQRCode")
    @ApiOperation("获取二维码信息")
    public AjaxResult getQRCode()  {
        return AjaxResult.success(this.thirdPartyWeChatService.getQRCode());
    }


    @GetMapping("/getAccessToken")
    @ApiOperation("获取AccessToken")
    public String  getAccessToken(String authorizerAppid)  {
        return this.thirdPartyWeChatService.getAccessToken(authorizerAppid);
    }

    @GetMapping("/aaaen")
    @ApiOperation("获取callBack")
    public void callBack(HttpServletResponse resp)throws IOException{
        thirdPartyWeChatService.getaaa(resp);
    }

    @PostMapping("/menuClick/{appId}")
    public String handleMenuClickEvent(HttpServletRequest request, HttpServletResponse response,@PathVariable("appId")String appId) throws IOException {
        // 根据菜单点击事件的key进行相应的处理逻辑
        log.info("接收到点击事件【{}】",appId);
        // 返回相应的文字消息
        return thirdPartyWeChatService.getMsgByKey(request,response,appId);


    }



}
